import { createInterface } from "node:readline";
import circle from '../src';

async function main() {
  await loginUser();
  const wallets = await circle.wallet.listWallet();
  console.log("wallets:", wallets);
  const userInfo = await circle.user.userInfo();
  console.log("userInfo:", userInfo);
  const balanceOfWallet = await circle.wallet.getBalanceOfWallet();
  console.log("balanceOfWallet:", balanceOfWallet);
  console.log("require:", typeof(importScripts));
}

async function loginUser() {
  // check login status
  let response = await circle.wallet.listWallet();
  if (response.status === 200 && response.data) {
    console.log("user already logged in.");
    return;
  }

  response = await circle.user.sendVerifyCode({
    email: "lidh04@qq.com"
  });
  console.log("response:", response);

  let verifyCode;
  for await (const line of createInterface({ input: process.stdin })) {
    // Do something with `line` here.
    console.log(line);
    if (!isNaN(line) && line.length === 6) {
      verifyCode = line;
      break;
    } else {
      console.error("please input 6 digital for verify code.");
    }
  }

  response = await circle.user.login({
    email: "lidh04@qq.com",
    verifyCode,
  });
  console.log("response:", response);
}

main().catch(err => console.error(err));
